package com.java3_8;

//懒汉单例模式
public class Demo4 {
    private String name;
    private int age;

    private Demo4(String name, int age) {
        this.name = name;
        this.age = age;
    }
    private static Demo4 demo4 = null;
    public static Demo4 getDemo4(){
        if(demo4 == null){
            synchronized (Demo4.class) {
                demo4 = new Demo4("wangwu",20);
            }
        }
        return demo4;
    }

    @Override
    public String toString() {
        return "Demo4{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
